
import 'dart:math';

import 'package:flutter/material.dart';

void main() =>runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return MaterialApp(
        home:HYHomePage()
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return Scaffold(
        appBar: AppBar(
          title: Text("列表测试"),
        ),
        body:ListViewBuilderDemo2()
    );
  }
}


class ListViewBuilderDemo2 extends StatelessWidget {
  const ListViewBuilderDemo2({
    super.key,
  });
  /*
   * 需要懒加载时
   * 用ListView.builder
   * */
  @override
  Widget build(BuildContext context) {
    //ListView.separated选项来创建单独的列表行小部件和分隔小部件
    return ListView.separated(
        itemCount: 100,
        //itemExtent: 60,
        itemBuilder: (BuildContext ctx,int index){
          return Text("Hello world:$index",style: TextStyle(fontSize: 20),);
        },
        separatorBuilder:(BuildContext ctx,int index){
          return Divider(color: Colors.red,);
        }
    );

  }
}

class ListViewDemo1 extends StatelessWidget {
  const ListViewDemo1({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    /*
    * ListView
    * 列表数据是确定的时候用
    * */
    return ListView(
      children: List.generate(100, (index) {
        return ListTile(
          leading: Icon(Icons.people),
          trailing: Icon(Icons.delete),
          title: Text("联系人${index+1}"),
          subtitle: Text('联系人的电话号码：12691820664'),
        );
      }),
    );
  }
}




